    #include "trap.h"
#include "inst_test.h"
#include "asm/regdef.h"
#include "asm/asm.h"
    .set noreorder
    .set noat 
    .global main 
    .text 

main:
    # 初始化
    ori $t0, $zero, 0x1000      # $t0 = 0x1000 (内存基址)
    ori $t1, $zero, 0x1234      # $t1 = 0x1234
    sw $t1, 0($t0)              # 存储$t1到$t0地址

    # 加载后立即使用，触发暂停
    lw $t2, 0($t0)              # 加载内存到$t2
    add $t3, $t2, $t1           # $t3 = $t2 + $t1 (依赖$t2，可能导致暂停)
    sub $t4, $t3, $t2           # $t4 = $t3 - $t2
    xor $t5, $t4, $t3           # $t5 = $t4 ^ $t3

    # 使用加载指令触发多次暂停
    lw $t6, 4($t0)              # 加载内存到$t6
    or $t7, $t6, $t5            # $t7 = $t6 | $t5 (依赖$t6)
    andi $t8, $t7, 0xFF         # $t8 = $t7 & 0xFF

    # 检查暂停逻辑
    ori $s0, $zero, 3           # $s0 = 3
loop3:
    lw $s1, 8($t0)              # 加载$s1
    add $s2, $s1, $s0           # 使用$s1
    sub $s0, $s0, 1             # $s0 -= 1
    bne $s0, $zero, loop3       # 如果$s0 != 0，继续循环
    nop                         # 延迟槽
    HIT_GOOD_TRAP

inst_error:
    HIT_BAD_TRAP
    

